package org.dromara.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.system.domain.XfNews;
import org.dromara.system.domain.XfUserReview;
import org.dromara.system.domain.query.XfUserReviewQuery;
import org.dromara.system.domain.vo.XfNewsVo;
import org.dromara.system.domain.vo.XfUserReviewVo;
import org.dromara.system.mapper.XfUserReviewMapper;
import org.dromara.system.service.IXfUserReviewService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class XfUserReviceServiceImpl extends ServiceImpl<XfUserReviewMapper, XfUserReview> implements IXfUserReviewService {

    @Override
    public TableDataInfo<XfUserReviewVo> selectPageXfUserReviewList(XfUserReviewQuery query) {
        Page<XfUserReview> page = new Page<>(query.getPageNum(), query.getPageSize());
        LambdaQueryWrapper<XfUserReview> wrapper = Wrappers.lambdaQuery();

        // 根据评论ID查询
        wrapper.eq(query.getId() != null, XfUserReview::getId, query.getId());

        // 根据公司ID查询
        wrapper.eq(query.getCompanyId() != null, XfUserReview::getCompanyId, query.getCompanyId());

        // 根据状态查询
        wrapper.eq(query.getStatus() != null, XfUserReview::getStatus, query.getStatus());

        // 根据用户ID查询
        wrapper.eq(query.getUserId() != null, XfUserReview::getUserId, query.getUserId());

        // 根据评论内容模糊查询
        wrapper.like(StringUtils.isNotBlank(query.getContent()), XfUserReview::getContent, query.getContent());

        // 按创建时间降序排列
        wrapper.orderByDesc(XfUserReview::getCreatedAt);
        Page<XfUserReviewVo> result = baseMapper.selectPageXfUserReviewList(page, wrapper);
        return TableDataInfo.build(result);
    }

    @Override
    public List<XfUserReviewVo> selectXfUserReviewList(XfUserReviewQuery query) {
        return baseMapper.queryList(query);
    }

    @Override
    public XfUserReviewVo selectXfUserReviewById(Long id) {
        return baseMapper.selectVoById(id);
    }

    @Override
    public boolean insertXfUserReview(XfUserReview userReview) {
        return this.save(userReview);
    }

    @Override
    public boolean updateXfUserReview(XfUserReview userReview) {
        return this.updateById(userReview);
    }

    @Override
    public int deleteXfUserReviewById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public int deleteXfUserReviewByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(List.of(ids));
    }
}
